﻿using UnityEngine;
using System.Collections;
using Dict.Blo;

namespace UI
{
    public class UIUnionFightHeroInfo : MonoBehaviour
    {
        public UITexture heroIcon;
        public UILabel heroName;

        public UILabel heroHp;
        public UISprite heroHpBar;

        public UISprite[] heroAngleBars;
        public void Init()
        {
            SetHeroIcon();
            SetHeroHp();
            SetHeroAnger();
        }

        void SetHeroIcon()
        {
            var leaderHero = StaticData.playerData.InstPlayerData.GetBattleCamp(1).hero;

            heroIcon.GetComponent<TextureKit>().iconType = TextureIcon.HERO;
            heroIcon.GetComponent<TextureKit>().textureName = leaderHero.heroData.iconName;
            heroName.text = StaticData.playerData.name;
        }

        public void SetHeroHp()
        {
            var playerData = UIUnionFightRunMap.GetNetData().netActor;

            if (playerData == null)
                return;

            float curHp = playerData.currentHp;
            float maxHp = playerData.MaxHp;

            var inHp = (int)curHp;
            var inMaxHp = (int)maxHp;

            heroHp.text = inHp + "/" + "" + inMaxHp;
            heroHpBar.fillAmount = curHp / maxHp;
        }

        void Update()
        {
            SetHeroHp();
        }

        public void SetHeroAnger()
        {
            float maxAngle = (float)DictConfigBlo.GetMaxAnger();
            float curAngle = UIUnionFightRunMap.GetNetData().netActor.Anger;

            float value = curAngle * 3f / maxAngle;

            for (int i = 0; i < 3; i++)
            {
                heroAngleBars[i].fillAmount = Mathf.Clamp01(value);
                value = value - 1f;
            }
        }
    }
}
